﻿using FluentValidation;
using Production.CommonLib.Models;

namespace Production.CommonLib.Validators;

public class ProductionResourceEditValidator : AbstractValidator<ProductionResourceEditRequestDto>
{

    public ProductionResourceEditValidator()
    {
        
    }

    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result =
            await ValidateAsync(ValidationContext<ProductionResourceEditRequestDto>.CreateWithOptions(
                (ProductionResourceEditRequestDto)model,
                x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}